import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store';

function addPage (payload) {
  store.dispatch({type: 'pages/addPage', payload});
}
function registerPage(route = {}, children = []) {
  const {
    path,
    component,
    name,
    components,
    redirect,
    props,
    alias,
    beforeEnter,
    meta,
    caseSensitive,
    pathToRegexpOptions,

    title,
    image,
    tags,
  } = route;

  addPage({title, name, path, image, tags});

  return {
    path,
    component,
    name,
    components,
    redirect,
    props,
    alias,
    beforeEnter,
    meta,
    caseSensitive,
    pathToRegexpOptions,
    children,
  }
}

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/home'),
  },
  registerPage(require('../views/echarts-3d-map').default),
];

const router = new VueRouter({
  routes
});

export default router;
